package com.wlx.common.core.utils;

import com.wlx.common.core.constant.CustomUserCacheConstants;
import com.wlx.common.core.text.Convert;

import javax.servlet.http.HttpServletRequest;

/**
 * 权限获取工具类
 * 
 * @author wlx
 */
public class PortalSecurityUtils
{

    /**
     * 获取用户ID
     */
    public static String getUserUuid()
    {
        return Convert.toStr(ServletUtils.getRequest().getHeader(CustomUserCacheConstants.DETAILS_USER_ID));
    }

    /**
     * 获取请求token
     */
    public static String getToken()
    {
        return getToken(ServletUtils.getRequest());
    }

    /**
     * 根据request获取请求token
     */
    public static String getToken(HttpServletRequest request)
    {
        String token = ServletUtils.getRequest().getHeader(CustomUserCacheConstants.HEADER);
        if (StringUtils.isNotEmpty(token) && token.startsWith(CustomUserCacheConstants.TOKEN_PREFIX))
        {
            token = token.replace(CustomUserCacheConstants.TOKEN_PREFIX, "");
        }
        return token;
    }
}
